/**
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index/index'),
        meta: {
          title: '首页',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/organization',
    component: Layout,
    redirect: 'noRedirect',
    name: 'organization',
    meta: { title: '机构管理', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'student-list',
        name: 'student-list',
        component: () => import('@/views/organization/index'),
        meta: { title: '机构管理', icon: 'user-graduate' },
      },
    ],
  },
  {
    path: '/teacher-management',
    component: Layout,
    redirect: 'noRedirect',
    name: 'teacher-management',
    meta: { title: '讲师管理', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'teacher-list',
        name: 'teacher-list',
        component: () => import('@/views/teacherManagement/index'),
        meta: { title: '讲师管理', icon: 'chalkboard-teacher' },
      },
    ],
  },
  {
    path: '/student-management',
    component: Layout,
    redirect: 'noRedirect',
    name: 'student-management',
    meta: { title: '学员管理', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'student-list',
        name: 'student-list',
        component: () => import('@/views/studentManagement/index'),
        meta: { title: '学员管理', icon: 'user-graduate' },
      },
    ],
  },
  {
    path: '/system',
    component: Layout,
    redirect: 'noRedirect',
    name: 'system',
    meta: { title: '系统管理', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'setting',
        name: 'setting',
        component: () => import('@/views/system/setting/index'),
        meta: { title: '机构设置' },
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role/index'),
        meta: { title: '权限管理' },
      },
      {
        path: 'user-list',
        name: 'user-list',
        component: () => import('@/views/system/user/index'),
        meta: { title: '人员管理' },
      },
      {
        path: 'course-type-list',
        name: 'course-type-list',
        component: () => import('@/views/system/courseType/index'),
        meta: { title: '课程分类' },
      },
    ],
  },
  {
    path: '/error',
    component: EmptyLayout,
    redirect: 'noRedirect',
    name: 'Error',
    meta: { title: '错误页', icon: 'bug' },
    hidden: true,
    children: [
      {
        path: '401',
        name: 'Error401',
        component: () => import('@/views/401'),
        meta: { title: '401' },
      },
      {
        path: '404',
        name: 'Error404',
        component: () => import('@/views/404'),
        meta: { title: '404' },
      },
    ],
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
